# Contributor: prspkt <prspkt@protonmail.com>
# Maintainer: prspkt <prspkt@protonmail.com>
pkgname=synapse-bt
pkgver=1.0
pkgrel=4
pkgdesc="Flexible and fast BitTorrent daemon"
url="https://github.com/Luminarys/synapse"
arch="all !aarch64 !s390x !riscv64 !loongarch64" # Cargo (aarch64 due to MAP_32BIT)
license="ISC"
pkgusers="synapse-bt"
pkggroups="synapse-bt"
makedepends="cargo openssl-dev cargo-auditable"
install="synapse-bt.pre-install"
subpackages="$pkgname-openrc $pkgname-cli:cli"
source="synapse-bt-$pkgver.tar.gz::https://github.com/Luminarys/synapse/archive/$pkgver.tar.gz
	openssl3.patch
	synapse-bt.initd
	"
builddir="$srcdir"/synapse-$pkgver


build() {
	cargo auditable build --release --all --locked
}

check() {
	cargo test --release
}

package() {
	mkdir -p "$pkgdir"/usr/bin
	install -Dm755 target/release/synapse \
		"$pkgdir"/usr/bin/synapse-bt
	install -D -m755 "$srcdir"/synapse-bt.initd \
		"$pkgdir"/etc/init.d/synapse-bt
	install -d -o synapse-bt -g synapse-bt \
		"$pkgdir"/var/lib/synapse-bt \
		"$pkgdir"/var/log/synapse-bt
	install -D -m644 -o synapse-bt -g synapse-bt \
		"$builddir"/example_config.toml \
		"$pkgdir"/var/lib/synapse-bt/.config/synapse.toml
}

cli() {
	pkgdesc="$pkgdesc (cli)"
	install -Dm755 "$builddir"/target/release/sycli \
		"$subpkgdir"/usr/bin/sycli
}

sha512sums="
d3caf0a4ca0e7a63dff07ec15bbbf2dc02736c6ba88c4fbece960af7223f7df8b176dc917518a9ac3f8692aa59c321cb9cbe2a0250a2dddbf520706e379be981  synapse-bt-1.0.tar.gz
1a2c79613cb6c155cf3e41939360438462e8e0337d3af6eab4c288797a256ec4c986a052de78d04d57ac039a7d06e1b42733bae37699ad58e8ca5a25a02aa4ea  openssl3.patch
82f8edef196cf15369ba4e6d83f289764fe6f94715f79b27803b7ef87317036cecaf2e497d4858d56727fe101d466d141addfc78b0396813b0edafde3c761d31  synapse-bt.initd
"
